package com.dubbo.sbdconsumer;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dubbo.sbdinterface.CommonService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.annotation.PostConstruct;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

@RestController
public class CommonController {

    @Reference
    private CommonService commonService;

    @PostConstruct
    public void run() throws ClassNotFoundException, SQLException {
        final List list = commonService.getList("select * from t_exam");
        System.out.println(list);
    }

    @GetMapping("/hello")
    public Mono<String> hello() {
        return Mono.just("Welcome to reactive world ~");
    }

    @GetMapping("/hello2")
    public Mono<List<Integer>> hello2() {
        return Mono.just(Arrays.asList(1, 2, 3, 4, 5));
    }
}